
package com.zsrt.day0523.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

public class jdbc01 {

	private static String url="jdbc:oracle:thin:@192.168.3.169:1521:xe";
	//system为登陆oracle数据库的用户名     
    private static String user="jiamengju";    
    //manager为用户名system的密码     
    private static String password="123456";    
    public static Connection conn;    
    public static PreparedStatement ps;    
    public static ResultSet rs;    
    public static Statement st ;    
    //连接数据库的方法     
    public void getConnection(){    
    	try {    
            //初始化驱动包     
            Class.forName("oracle.jdbc.OracleDriver");    
            //根据数据库连接字符，名称，密码给conn赋值     
            conn=DriverManager.getConnection(url, user, password);    
                
        } catch (Exception e) {    
            // TODO: handle exception     
            e.printStackTrace();    
        }   
    }
     
  //测试能否与oracle数据库连接成功     
     public static void main(String[] args) throws Exception {   
    	
        jdbc01 basedao=new jdbc01();    
        basedao.getConnection();    
        if(conn==null){    
            System.out.println("与oracle数据库连接失败！");    
        }else{    
            System.out.println("与oracle数据库连接成功！");    
            
        }    
     }   
	   
}
